package cpa.prowon.gui;

import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.ViewForm;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;

import cpa.prowon.gui.util.ColorManager;
import cpa.prowon.gui.util.ImageUtil;

/**
 * Represents one part of the window. Intended to be subclassed
 * @author Chris
 */
abstract class WindowPart
{
	
	private Composite parent;
	private Composite contentsForm;
	private MainWindow mainWindow;
	
	abstract protected String getTitle();
	abstract protected String getIcon();
	abstract protected void createContents(Composite parent);
	
	/**
	 * Constructor
	 * @param MainWindow The main window
	 * @author Chris 
	 */
	public WindowPart(MainWindow aMainWindow)
	{
		super();
		setMainWindow(aMainWindow);
		createActions();
	}

	/**
	 * Get the parent
	 * @return The actual parent of the window part
	 * @author Chris
	 */
	protected Composite getParent()
	{
		return parent;
	}

	/**
	 * Set the parent
	 * @param Composite The actual parent of the window part
	 * @author Chris
	 */
	protected void setParent(Composite aParent)
	{
		parent = aParent;
	}

	/**
	 * Get the main window
	 * @return The main window
	 * @author Chris
	 */
	protected MainWindow getMainWindow()
	{
		return mainWindow;
	}

	/**
	 * Set the main window
	 * @param MainWindow The main window
	 * @author Chris
	 */
	protected void setMainWindow(MainWindow aMainWindow)
	{
		mainWindow = aMainWindow;
	}

	/**
	 * Get the form which is the parent of the contents
	 * @return The actual parent of the contents
	 * @author Chris
	 */
	protected Composite getContentsForm()
	{
		return contentsForm;
	}

	/**
	 * Register the file menu actions
	 * @param MenuManager The menu manager to put the actions in
	 * @author Chris
	 */
	public void registerFileMenuActions(MenuManager menuMgr)
	{
	}

	/**
	 * Register the edit menu actions
	 * @param MenuManager The menu manager to put the actions in
	 * @author Chris
	 */
	public void registerEditMenuActions(MenuManager menuMgr)
	{
	}

	/**
	 * Register the view menu actions
	 * @param MenuManager The menu manager to put the actions in
	 * @author Chris
	 */
	public void registerViewMenuActions(MenuManager menuMgr)
	{
	}

	/**
	 * Register the toolbar actions
	 * @param ToolBarManager The tool bar manager to put the actions in
	 * @author Chris
	 */
	public void registerToolBarActions(ToolBarManager toolBarMgr)
	{
	}

	/**
	 * Create the widgets
	 * @param Composite The parent to put the widgets in
	 * @author Chris
	 */
	public void createWidgets(Composite aParent)
	{
		setParent(aParent);
		createFrame();
		createContents(getContentsForm());
	}

	/**
	 * Create the actions for this window part
	 * @author Chris
	 */
	protected void createActions()
	{
	}

	/**
	 * Create the main frame
	 * @param Composite The parent to put the viewer into
	 * @author Chris
	 */
	protected void createFrame()
	{
		
		// Get the color manager
		ColorManager colMgr = ColorManager.getInstance();
		
		// Create the main view form
		ViewForm form = new ViewForm(parent, SWT.BORDER);
		form.marginHeight = 0;
		form.marginWidth = 0;

		// Create a label to simulate the window title bar
		CLabel label = new CLabel(form, SWT.LEFT);
		label.setText(getTitle());
		label.setImage(ImageUtil.getImage(getIcon()));
		label.setBackground(colMgr.getColorGradient(), colMgr.getColorGradientRatio());
		label.setForeground(colMgr.getColor(SWT.COLOR_WHITE));
		form.setTopLeft(label);

		// Create a sub form that will hold the different children
		contentsForm = new Composite(form, SWT.NONE);
		contentsForm.setLayout(new FillLayout());
		contentsForm.setBackground(colMgr.getColor(SWT.COLOR_WHITE));
	
		// Set the sub form into the category main form		
		form.setContent(contentsForm);
		
	}
	
}
